var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/configComponent/form/listener.ts
var listener_exports = {};
__export(listener_exports, {
  mergeEventHandler: () => mergeEventHandler
});
module.exports = __toCommonJS(listener_exports);
var listenerReg = /^on[A-Z]+/;
var propsReg = /^props([A-Z]+)/;
function mergeEventHandler() {
  let s = {};
  return function handleMerge(n, isReplace) {
    if (isReplace) {
      s = merge({}, n);
      return handleMerge;
    }
    if (!n)
      return converArraytoFunc(s);
    else {
      s = merge(s, n);
      return handleMerge;
    }
  };
  function merge(s2 = {}, n) {
    if (!n)
      return s2;
    Object.keys(n).forEach((key) => {
      if (key === "children" && n.children) {
        s2.children = merge(s2.children || {}, n.children);
      } else if (listenerReg.test(key) && typeof n[key] === "function") {
        if (s2[key]) {
          if (Array.isArray(s2[key]))
            s2[key].push(n[key]);
          else
            s2[key] = [s2[key], n[key]];
        } else
          s2[key] = n[key];
      } else if (typeof n[key] === "object") {
        s2[key] = merge(s2[key], n[key]);
      } else {
        s2[key] = n[key];
      }
    });
    return s2;
  }
  function converArraytoFunc(s2) {
    let x = {};
    Object.keys(s2).forEach((key) => {
      if (listenerReg.test(key)) {
        if (Array.isArray(s2[key])) {
          x[key] = function() {
            s2[key].forEach((item) => item(...arguments));
          };
        } else {
          x[key] = s2[key];
        }
      } else if (propsReg.test(key)) {
        const pkey = key.replace(propsReg, (match, $1) => {
          return $1.toLowerCase();
        });
        x[pkey] = s2[key];
      } else {
        x[key] = converArraytoFunc(s2[key]);
      }
    });
    return x;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  mergeEventHandler
});
